package ca.kooki.codesnippet.core;

import junit.framework.Assert;

import org.junit.Test;

public class IdentifierTest 
{

  
  
  @Test
  public void ToStringNoId()
  {
    Identifier id = new Identifier(Identifier.class);
    Assert.assertEquals("-", id.toString());
  }

  @Test
  public void ToStringHasId()
  {
    Identifier id = new Identifier(Identifier.class);
    id.setId("10");
    Assert.assertEquals("10", id.toString());
  }

  
  @Test
  public void NotEqualsNull()
  {
    Identifier id = new Identifier(Identifier.class);
    Assert.assertFalse(id.equals(null));
    Assert.assertFalse(id.equals("blah"));
  }

  @Test
  public void NotEqualsWrongId()
  {
    Identifier id = new Identifier(Identifier.class);
    Identifier compareTo = null;
    
    id.setId("10");
    compareTo = new Identifier(Identifier.class);
    Assert.assertFalse(id.equals(compareTo));
    Assert.assertFalse(compareTo.equals(id));

    compareTo.setId("11");
    Assert.assertFalse(id.equals(compareTo));
    Assert.assertFalse(compareTo.equals(id));
  }

  @Test
  public void EqualsNoId()
  {
    Identifier id = new Identifier(Identifier.class);
    Identifier compareTo = new Identifier(Identifier.class);
    Assert.assertTrue(id.equals(compareTo));
  }

  @Test
  public void EqualsSameId()
  {
    Identifier id = new Identifier(Identifier.class);
    Identifier compareTo = new Identifier(Identifier.class);
    
    id.setId("10");
    compareTo.setId("10");
    
    Assert.assertTrue(id.equals(compareTo));
  }
  
  @Test
  public void IsOfficial()
  {
    Identifier id = new Identifier(Identifier.class);
    Assert.assertEquals(false, id.isOfficial());
    id.setId("10");
    Assert.assertEquals(true, id.isOfficial());
  }
  
  @Test(expected=UnsupportedOperationException.class)
  public void getIdNotSetYet()
  {
    Identifier id = new Identifier(Identifier.class);
    id.getId();
  }

  @Test
  public void cannotSetIdToSameNumberMultipleTimes()
  {
    Identifier id = new Identifier(Identifier.class);
    id.setId("10");
    id.setId("10");
    Assert.assertEquals("10", id.getId());
  }

  
  @Test(expected=UnsupportedOperationException.class)
  public void cannotSetIdToDifferentNumber()
  {
    Identifier id = new Identifier(Identifier.class);
    id.setId("10");
    id.setId("11");
  }

  
  @Test
  public void getIdOkay()
  {
    Identifier id = new Identifier(Identifier.class);
    id.setId("10");
    Assert.assertEquals("10", id.getId());
  }

}
